﻿app.views.Rankings = Ext.extend(Ext.Panel, {
    scroll: true,
    id: 'views.Rankings',
    dockedItems: [{
        xtype: 'toolbar',
        dock: 'top',
        title: 'Ratings'
    }
    ],
    items: [],
    initComponent: function () {
        // Set the variable list (part of Activity History) to a templated list
        this.list = new Ext.List({
            disableSelection: true,
            id: 'views.Rankings.restaurantList',
            store: restaurantStore,
            scroll: false,
            activeCls: 'list-item-active', // Used for swipe-delete button
            scope: this,
            element: null, // Stores the currently visible delete button

            itemTpl: [
                "<div style='text-shadow:1px 1px 0px #FFFFFF;filter:dropshadow(color=#FFFFFF, offx=1, offy=1)' class='detailsContainer'>",
                    "<img style='float:left;margin:0 10px 0 0' src='{IMAGE_LOCATION}'/><p>{RESTAURANT_CATEGORY_NAME}</p>",
                    "<p style='font-size:13px'>{STREET_ADDRESS1}</p>",
                    "<p style='font-size:13px'>{STREET_ADDRESS2}</p>",
                    "<p style='font-size:13px'>{CITY}, {STATE}, {ZIP}</p>",
                "</div>"
            ],

            // Deletes list item if tapped, hides it if anything else is tapped
            onItemTap: function (item, index, e) {
                Ext.getCmp('backButton').prevCard = app.views.rankings;
                Ext.dispatch({
                    controller: app.controllers.navigation,
                    action: 'showRestaurantDetails',
                    record: restaurantStore.getAt(index)
                });
            },
            // Hides all visible delete buttons
            deactivateAll: function () {
                if (this.element && this.element.hasCls(this.activeCls)) {
                    this.element.removeCls(this.activeCls);
                }
            }
        });

        // Put the list into the main panel
        this.items.push(this.list);
        app.views.Rankings.superclass.initComponent.call(this); // Must go at the end of initComponent. 
    }
});
